package edu.fsu.cs.SHPE;

import java.net.ConnectException;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class VenueListAdapter extends BaseAdapter {

	private final static String TAG = "SHPE.VenueListAdapter";
	private VenueContainer venueContainer;
	private LayoutInflater inFlate;
	
	public VenueListAdapter(Context context, String url) throws ConnectException{
		venueContainer = new VenueContainer(url);
		inFlate = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
	}

	@Override
	public int getCount() {
		return venueContainer.size();
	}

	@Override
	public Object getItem(int position) {
		return venueContainer.get(position);
	}

	@Override
	public long getItemId(int position) {
		return venueContainer.get(position).getId();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		Log.i(TAG, "position " + position);

		if(convertView == null)
			convertView = inFlate.inflate(R.layout.venueitem, null);
		
		TextView tmp;	
		Venue tmpVenue = venueContainer.get(position);

		if(tmpVenue.getThumbnail() != null){
			ImageView image = (ImageView)convertView.findViewById(R.id.imgPhoto);
			image.setImageDrawable(tmpVenue.getThumbnail());
			image.setVisibility(View.VISIBLE);
		}
		
		if(tmpVenue.getName() != null){
			tmp = (TextView)convertView.findViewById(R.id.txtName);
			tmp.setText(tmpVenue.getName());
			tmp.setVisibility(TextView.VISIBLE);
		}
		

		return convertView;
	}

}
